package com.example.SocialApplication.adapters;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;
import java.util.Locale;

public class SectionsPagerAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;
    private IPageTitleSetter mIPageTitleSetter;

    public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    public SectionsPagerAdapter(FragmentManager fm, List<Fragment> fragments, IPageTitleSetter iPageTitleSetter) {
        super(fm);
        this.fragments = fragments;
        this.mIPageTitleSetter = iPageTitleSetter;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = fragments.get(position);
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mIPageTitleSetter != null) {
            return mIPageTitleSetter.setTitle(position, Locale.getDefault());
        }
        return null;
    }

    public void setPageTitle(IPageTitleSetter iPageTitleSetter) {
        mIPageTitleSetter = iPageTitleSetter;
    }
}
